<template>
  <div>
  	<crud-form
        :field-list="fieldList"
        :exportFn="exportFn"
        :columnNum = "'6'"
        :api="cx"
        :queryParam="test"
        ref="crudForm"
        tableOptionName="操作"
        tableOptionWidth="260"
      >
        <template slot="tableOption" slot-scope="{ index, row }">
          	<el-button @click="xgopen(row)" class="common-btn">修改</el-button>
            <el-button @click="Delete(row)" class="delete-btn">删除</el-button>
        </template>
      </crud-form>

    <div>
      <!-- 修改二级 -->
      <div>
        <el-dialog
          title="修改字典"
          :visible.sync="xiugai"
          width="500px"
          class="yw"
          @cloce="cloce_"
          :modal-append-to-body="false"
          :close-on-click-modal="false"
          top="20vh"
          style="left: 85px"
        >
          <el-form
            ref="sizeForm"
            :model="sizeForm"
            :rules="this.$parent.$refs.erji.rules"
            label-width="80px"
            size="small"
            style="padding: 0px 20px;"
          >
            <el-form-item label="上级字典">
              <span>{{sizeForm.parentName}}</span>
            </el-form-item>
            <el-form-item label="字典名称" prop="name">
              <el-input v-model="sizeForm.name" class="kz" clearable />
            </el-form-item>
            <el-form-item label="字典码" prop="value">
              <el-input
                v-model="sizeForm.value"
                class="kz"
                clearable
              />
            </el-form-item>
            <el-form-item label="排序" prop="sortNo">
              <el-input
                v-model="sizeForm.sortNo"
                class="kz"
                clearable
              />
            </el-form-item>
            <el-form-item label="备注">
              <!-- <textarea v-model="sizeForm.remark" class="kz" clearable /> -->
              <el-input
              type="textarea"
              placeholder="请输入内容"
              v-model="sizeForm.remark"
              maxlength="128"
              show-word-limit
              class="kz"
            />
            </el-form-item>
          </el-form>
          <div slot="footer">
            <el-button size="small"  @click="addBiaoge('sizeForm')" class="btnSpace bouncedHold listBTN">确定</el-button>
            <el-button size="small" @click="xiugai = false" class="cancelBTN listBTN">取消</el-button>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
	import crudForm from "@/components/crudForm/index";
import {
  cx,
  remove,
  xiuGai,
  findByParentId,
} from "../../../../api/system/dict";

export default {
  name: "biaoge",
  components: {
			crudForm
	},
  data() {
    return {
      tableData: [],
      params: {
        value: "",
      },
      search: "",
      xiugai: false,
      deleteWin: false,
      sizeForm: {},
      treeid: "-1",
      test:{
      	parentId:-1
      },
      cx,
		  fieldList: [
		    { name: "字典名称", value: "name" },
		    { name: "字典码", value: "value" },
		    { name: "上级字典", value: "parentName" },
		    { name: "排序", value: "sortNo" },
		    { name: "备注", value: "remark" },
		  ],
    };
  },
  created() {
    
  },
	mounted() {
    
  },
  methods: {
    cloce_(){
    	this.sizeForm = {}
    },
    Delete(row) {
      const id = row.id;
      this.$confirm("此操作将永久删除该项数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        confirmButtonClass: "messagebox-button",
				cancelButtonClass: "messagebox-button"
      })
        .then(() => {
          remove(id)
            .then((res) => {
              if (res.code == "000000") {
                this.$message({
                  message: res.mesg,
                  type: "success",
                });
                this.$parent.$refs.tree.rests()
                //ress
                this.$refs.crudForm.getDataInit()
              } else {
                this.$message({
                  message: res.mesg,
                  type: "error",
                });
              }
            })
            .catch((res) => {
              this.$message({
                message: res.mesg,
                type: "error",
              });
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    // 修改
    xgopen(row) {
      //获取当前选择的列表数据
      this.xiugai = true;
      
      this.sizeForm = {
        id: row.id,
        name: row.name,
        value: row.value,
        paraName: row.paraName,
        sortNo: row.sortNo,
        parentName: row.parentName,
        remark:row.remark,
        parentId: row.parentId,
      };
    },
    exportFn(){
    	return false;
    },
    addBiaoge(formName) {
      // 发送当前列表修改后的数据
      this.$refs[formName].validate((valid) => {
        if (valid) {
          xiuGai({
            id: this.sizeForm.id,
            name: this.sizeForm.name,
            value: this.sizeForm.value,
            paraName: this.sizeForm.paraName,
            remark:this.sizeForm.remark,
            sortNo: this.sizeForm.sortNo,
            parentId: this.sizeForm.parentId,
          })
            .then((res) => {
            	if(res.code == "000000"){
	              this.$message({
	                message: "修改成功",
	                type: "success",
	              });
	              this.xiugai = false;
	              this.params.value = this.sizeForm.parentId;
	              this.$parent.$refs.tree.rests()
	              //ress
	              this.$refs.crudForm.getDataInit()
             }else{
             	this.$message.error("修改失败");
             }
            })
            .catch((err) => {
              this.$message.error("修改失败");
              this.xiugai = false;
            });
        }
      });
    },
  },
};
</script>



